package fauxman.states;

import fauxman.DynamicElements.Ghost;
import fauxman.model.WorldModel;
import fauxman.utilities.ActionUtil;

public class PurgatoryUpState extends GhostHouseState{
	private static PurgatoryUpState instance;
	private static final int[] target = {13,13};
	
	private PurgatoryUpState(){
	}
	
	public static PurgatoryUpState getInstance(){
		if (instance==null)
			instance = new PurgatoryUpState();
		return instance;
	}
	
	
	//Vulnerable Ghost doesnt have a target since it wanders aimlessly
	public int[] getTarget(WorldModel model, Ghost g) {
		return target;
	}
	@Override
	public void reactToCurrentDiscretePosition(WorldModel model, Ghost g){
		if(g.getDiscretePosition().y == target[1]){
			g.setCurrentDirection(ActionUtil.SOUTH);
			g.setLookAhead(ActionUtil.getNextPosition(g.getDiscretePosition(), ActionUtil.DISCRETE_UNITS, g.getCurrentDirection()));
			if(g.getChangeToLeaving()){
				System.out.println("Ghost \""+ g + "\" changing to LeavingHouseState");
				g.hitGhostHouseTarget(LeavingHouseState.getInstance());
				g.setNextDirection(getNextDirection(model, g));	
			}else{
				System.out.println("Ghost \""+ g + "\" changing to PurgatoryDownState");
				g.hitGhostHouseTarget(PurgatoryDownState.getInstance());
				g.setNextDirection(ActionUtil.SOUTH);
			}
			//g.setReversalBlock(g.getDiscretePosition().x, PurgatoryDownState.getInstance().getTarget(null, g)[1]);
		}
	}
	
	@Override
	public boolean shouldCalculateNextDirection(WorldModel model, int disX, int disY, int lookaheadX, int lookaheadY){
		return false;
	}
}
